package com.hong610.controller.base;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 控制器基类
 * Created by Hong on 2016/12/7.
 */
public class BaseController implements ServletContextAware {

    /**
     * 日志
     **/
    protected final Logger log = LoggerFactory.getLogger(this.getClass());
    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected HttpSession session;
    protected ServletContext application;
    protected Map<String, Object> map;

    @ModelAttribute
    public void setReqAndRes(HttpServletRequest request, HttpServletResponse response, HashMap<String, Object> map) {
        this.request = request;
        this.response = response;
        this.session = request.getSession();
        this.map = map;
    }

    @Override
    public void setServletContext(ServletContext arg0) {
        this.application = arg0;
    }

    /**
     * 获取传递过来的参数
     */
    public String getParameter(String key) {
        return request.getParameter(key);
    }
}
